package br.com.projeto.dao.hql;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import br.com.projeto.sakila.bean.Rental;
import br.com.projeto.sakila.bean.Staff;

public class StaffDao {
	private SessionFactory sessionFactory;
	private Session session;

	public StaffDao(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	
	public long buscarStaff(){
		long tempoInicial = System.currentTimeMillis(); 
		
		List<Staff> listaStaff = new ArrayList<>();
		try{
			session = sessionFactory.openSession();
			listaStaff = session.createQuery("from Staff").list();
			session.close();
		} catch (Exception e){
			System.err.println("Error");
		}
		long tempoFinal = System.currentTimeMillis(); 
		long tempo = tempoFinal - tempoInicial;
		return tempo;
	}
	
	public void listarStaff(List<Staff> lista){
		System.out.println("---------------------------");
		for (Staff staff : lista) {
			System.out.println("ID : " + staff.getId());
			System.out.println("first Name : " + staff.getFirstName());
			System.out.println("last Name : " + staff.getLastName());
			System.out.println("email : " + staff.getEmail());
			System.out.println("active : " + staff.getActive());
			System.out.println("username : " + staff.getUsername());
			System.out.println("password : " + staff.getPassword());
			//TODO:falta campos

			System.out.println("---------------------------");
		}
	}
}
